package com.example.demo;

import java.util.concurrent.*;
import java.util.concurrent.locks.*;

/**
 * @author wenl
 * @version V2.0
 * @project education
 * @package com.example.demo
 * @date 2020/4/7
 * @describe
 */
public class Test {
    static ScheduledExecutorService  es = Executors.newScheduledThreadPool(4);

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        for(int i=0; i < 6; i++){
            Future<String> future = es.submit(new Task(""+i));
            System.out.println(future.get());
        }
        es.shutdown();
    }

}

class Task implements Callable{
    private String name;

    public Task(String name){
        this.name=name;
    }

    public void run() {
        System.out.println("start task "+name);

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("end task "+name);
    }

    @Override
    public Object call() throws Exception {
        return "This is calling...";
    }
}